from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from routes import node_routes, auth_routes
from database.sqlite import engine, Base

# 创建数据库表
Base.metadata.create_all(bind=engine)

# 初始化FastAPI应用
app = FastAPI(title="Neo4j Manager API", description="Neo4j图数据库管理系统API")

# 添加CORS中间件
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # 生产环境应限制允许的源
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 注册路由
app.include_router(node_routes.router)
app.include_router(auth_routes.router)

# 根路径
@app.get("/")
async def root():
    return {"message": "欢迎使用Neo4j图数据库管理系统API"}